bpf: fix integer overflows
authorAlexei Starovoitov <ast@kernel.org>
Tue, 19 Dec 2017 04:12:00 +0000 (20:12 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 22 Dec 2017 14:12:23 +0000 (14:12 +0000)
commit1318c67e19aa39baf44110395a0703ae8694b596
treedb31a018e4c6c7caf29871334912fb9bb276fd4d
parente263a5d1653dc2af8cfcd40f8c2202870077a4ff
bpf: fix integer overflows

There were various issues related to the limited size of integers used in
the verifier:
 - `off + size` overflow in __check_map_access()
 - `off + reg->off` overflow in check_mem_access()
 - `off + reg->var_off.value` overflow or 32-bit truncation of
   `reg->var_off.value` in check_mem_access()
 - 32-bit truncation in check_stack_boundary()

Make sure that any integer math cannot overflow by not allowing
pointer math with large values.

Also reduce the scope of "scalar op scalar" tracking.

Fixes: f1174f77b50c ("bpf/verifier: rework value tracking")
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name bpf-fix-integer-overflows.patch
include/linux/bpf_verifier.h
kernel/bpf/verifier.c